home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
0920.ZIP
/
PAS2C.ARC
/
SAVEREG.H
< prev
next >
Wrap
Text File
|
1987-12-23
|
2KB
|
43 lines
/*
SAVEREG.H
The Turbo C compiler produces its best code when it is allowed to use
SI and DI as general registers. When Pascal is used to call a C function,
this works, because C functions that use SI and DI save and restore the
register values appropriately. If the C function calls a Pascal routine,
the Pascal routine is at liberty to destroy the values contained in SI
and DI. Turbo C provides an option (-r-) to support this, at the cost
of worsening code generation. The two macros in this file also solve the
problem, in a more efficient way. Every call from C to Pascal is to
be wrapped in a save_registers/restore_registers pair:
save_registers;
PASCAL_PROCEDURE();
restore_registers;
save_registers saves the contents of SI and DI before the call,
restore_registers restores the contents of SI and DI after the call.
The PASCAL program must make a POINTER called __rsp available globally,
and must point it to an area to be used as a save stack. 2 words are
used on this stack every time save_registers is used.
var
__rsp : Pointer;
SiDiStack : array [0..10] of Word;
...
begin
__rsp := @SiDiStack[0];
...
end.
save_registers and restore_registers are implemented as macros for
efficiency.
*/
#define save_registers {IMPORT WORD FAR *_rsp; *_rsp++ = _SI; *_rsp++ = _DI;}
#define restore_registers {IMPORT WORD FAR *_rsp; _DI = *--_rsp; _SI = *--_rsp;}